package it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyResizableCell;

public class XY {
    public double x;
    public double y;

    public XY() {
        x = 0;
        y = 0;
    }

    public XY(double x, double y) {
        this.x = x;
        this.y = y;
    }

    public XY(XY p) {
        this.x = p.x;
        this.y = p.y;
    }

    public void setValue(XY p) {
        this.x = p.x;
        this.y = p.y;
    }

    public void setValue(double px, double py) {
        this.x = px;
        this.y = py;
    }

    public boolean equals(XY p) {
        return ((p.x == x) && (p.y == y));
    }

    public int hashCode() {
        int hash = 3;
        hash = 41 * hash + hash ^ (int) this.x;
        hash = 41 * hash + hash ^ (int) this.y;
        return hash;
    }

    public boolean equals(Object point) {
        XY _point = (XY) point;
        return (((int) _point.x == (int) x) && ((int) _point.x == (int) x));
    }

    public void add(XY point) {
        this.x += point.x;
        this.y += point.y;
    }

    public void sub(XY point) {
        this.x -= point.x;
        this.y -= point.y;
    }

    public static XY sumOf(XY a, XY b) {
        XY result = new XY(a);
        result.add(b);
        return result;
    }

    public static XY subtractionOf(XY a, XY b) {
        XY result = new XY(a);
        result.sub(b);
        return result;
    }

    public static double distanceOf(XY a, XY b) {
        double dx = a.x - b.x;
        double dy = a.y - b.y;

        return Math.sqrt(dx * dx + dy * dy);
    }

    public String toString() {
        return "(" + x + "," + y + ")";

    }
}